package com.symbio.ishenapi.doctor.controller;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;
import com.symbio.ishenapi.common.controller.BaseController;
import com.symbio.ishenapi.doctor.model.TmDoctorServerAttribute;
import com.symbio.ishenapi.doctor.model.TmDoctorTherapy;
import com.symbio.ishenapi.doctor.model.TmHospitalDepartment;
import io.jboot.web.controller.annotation.RequestMapping;
import vo.DoctorVO;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/TmDoctorUser")
public class TmDoctorUserController extends BaseController {

    public void serverType(){  //服务类型查询
        DoctorVO user = (DoctorVO) getReqBodyObject(DoctorVO.class);
        List<Record> server = TmDoctorServerAttribute.dao.findDoctorServer(user);
        if(!StrKit.isBlank(user.getDepartmentId())){
            boolean isStatus = TmHospitalDepartment.dao.isDepStatus(user.getDepartmentId());
            Map<String,Object> map = new HashMap<>();
            map.put("serverStatus",server);
            map.put("devStatus",isStatus);
            renderJsonRet(map);
        }else {
            renderJsonRet(server);
        }
    }

    ///医生ID生成二维码
    public void getQrCode(){
        String doctorId = getPara("doctorId");
        String newDocorId="http://www.ishen365.com/?id="+doctorId;
        renderQrCode(newDocorId,200,100);
    }

    public void updTmDoctorTherapy(){         //设置医生停诊
        TmDoctorTherapy user = (TmDoctorTherapy) getReqBodyObject(TmDoctorTherapy.class);
        TmDoctorTherapy u = TmDoctorTherapy.dao.findById(user.getUserId());
        if (user != null) {
            if (!StrKit.isBlank(user.getUserId().toString())) u.setUserId(user.getUserId());
            if (!StrKit.isBlank(user.getState())) u.setState(user.getState());
            if (!StrKit.isBlank(user.getWhen())) u.setWhen(user.getWhen());
            if (u.update()) {
                renderJsonRet(user.getId());
            } else {
                renderJsonError(40005);
            }
        }else{
            System.out.println("数据库中用户信息为空");
            renderJsonError(40003);
            return;
        }
    }

//*****以下作废的方法********************************************************************************************************

    //***此方法迁移到后端服务 2018/11/12
    /*public void saveDoctorUser(){       //添加医生的个人信息
        TmDoctorUser user = (TmDoctorUser) getReqBodyObject(TmDoctorUser.class);
        user.setCreateTtime(new Date());
        if (user.getUserName() == null || "".equals(user.getUserName())) {
            renderJsonError(40003, "姓名");
        }else if (user.getUserMobilePhone() == null || "".equals(user.getUserMobilePhone())){
            renderJsonError(40003, "电话");
        }else if (user.getUserSex() == null || "".equals(user.getUserSex())){
            renderJsonError(40003, "性别");
        }else if (user.getUserCity() == null || "".equals(user.getUserCity())){
            renderJsonError(40003, "所在城市");
        }else if (user.getUserBirthday() == null || "".equals(user.getUserBirthday())){
            renderJsonError(40003, "出生日期");
        }
        else {
            user.save();
            renderJsonRet(40001);
        }
    }*/

    //***此方法迁移到后端服务 2018/11/12
    /*public void findDoctorUser(){       //显示医生信息
        BigInteger id = new BigInteger(getPara("id"), 10);
        TmDoctorUser item = TmDoctorUser.dao.findById(id);
            if (item == null ) {
                renderJsonError(40003);
                return;
            }
        renderJsonRet(item);
    }*/

    //***此方法迁移到后端服务 2018/11/12
    /*public void updTmDoctorUser(){         //修改医生信息
        TmDoctorUser user = (TmDoctorUser) getReqBodyObject(TmDoctorUser.class);
        TmDoctorUser u = TmDoctorUser.dao.findById(user.getId());
        if (u != null) {
            if (!StrKit.isBlank(user.getUserName())) u.setUserName(user.getUserName());
            if (!StrKit.isBlank(user.getUserEmail())) u.setUserEmail(user.getUserEmail());
            if (!StrKit.isBlank(user.getUserNickName())) u.setUserNickName(user.getUserNickName());
            if (!StrKit.isBlank(user.getUserSex())) u.setUserSex(user.getUserSex());
            if (!StrKit.isBlank(user.getUserCity())) u.setUserCity(user.getUserCity());
            if (!StrKit.isBlank(user.getUserIdCard())) u.setUserIdCard(user.getUserIdCard());
        if (user.getUserBirthday() != null) u.setUserBirthday(user.getUserBirthday());////生日保存有问题 待修改
            if (!StrKit.isBlank(user.getUserDetailedAddress())) u.setUserDetailedAddress(user.getUserDetailedAddress());
            if (!StrKit.isBlank(user.getUserPostCode())) u.setUserPostCode(user.getUserPostCode());
            if (!StrKit.isBlank(user.getUserHeadPortrait())) u.setUserHeadPortrait(user.getUserHeadPortrait());
            if (u.update()) {
                renderJsonRet(user.getId());
            } else {
                renderJsonError(40005);
            }
        }else{
            System.out.println("数据库中用户信息为空");
            renderJsonError(40003);
            return;
        }
    }*/

    //***此方法迁移到后端服务 2018/11/12
    /*
     * 我的工作室
     * */
    /*public void findWork(){ //查询医生信息
        TmDoctorUser user = (TmDoctorUser) getReqBodyObject(TmDoctorUser.class);
        renderJsonRet(TmDoctorUser.dao.selectDoctor(user.getId()));
    }*/

    //***此方法迁移到后端服务 2018/11/12
    ////根据多个医生ID 查询对应的信息
    /*public void serchDoctorByMoreId(){
        String doctorId = getPara("doctorId");
        System.out.println("获取的医生列表ID为"+doctorId);
        renderJsonRet(TmDoctorUser.dao.findTmPatientDoctorList(doctorId));
    }*/

    //***此方法迁移到后端服务 2018/11/12
    /**
     *
     *
     * @Author GuoShunYou
     * @Description 根据doctorType角色 查询医生id
     * @date 上午 10:30   2018/11/2
     * @return void
     */

/*public void getdoctorId(){
        TmDoctorUser user = (TmDoctorUser) getReqBodyObject(TmDoctorUser.class);
        List<TmDoctorUser> list=TmDoctorUser.dao.getdoctorId(user.getDoctorType());
        if(list.size()<=0){
            renderJsonError(40003,"该角色对应医生");
        }else{
            String str=list.get(0).getId().toString();
            for(int i=1;i<list.size();i++){
                str+= ","+list.get(i).getId().toString();
            }
            renderJsonRet(str);
        }
    }*/

    /**
     *
     *
     * @Author GuoShunYou
     * @Description TODO(简要描述此方法)
     * @date 下午 3:17   2018/11/2
     * @return void
     */
    /*public void getdoctorType(){}*/

    //***暂时没用到 2018/11/12
    /**
     *医生展示信息
     */
    /*public void  showDoctor(){       //医生信息展示
        String userId = getPara("id");
        renderJsonRet(TmDoctorUser.dao.showDoctor(userId));
    }*/

}
